const app = getApp();

// 班车相关API
const schedule = {
  // 获取班车列表
  getList(params) {
    return app.request({
      url: '/bus-schedules',
      data: params
    });
  },

  // 获取班车详情
  getDetail(id) {
    return app.request({
      url: `/bus-schedules/${id}`
    });
  },

  // 查询指定日期可用座位
  getAvailableSeats(scheduleId, date) {
    return app.request({
      url: `/bus-schedules/${scheduleId}/seats`,
      data: { date }
    });
  }
};

// 预约相关API
const reservation = {
  // 创建预约
  create(data) {
    return app.request({
      url: '/reservations',
      method: 'POST',
      data
    });
  },

  // 获取用户预约列表
  getList(status, page = 1, pageSize = 10) {
    return app.request({
      url: '/reservations',
      data: {
        status,
        page,
        page_size: pageSize
      }
    });
  },

  // 获取预约详情
  getDetail(id) {
    return app.request({
      url: `/reservations/${id}`
    });
  },

  // 取消预约
  cancel(id, reason) {
    return app.request({
      url: `/reservations/${id}/cancel`,
      method: 'POST',
      data: { reason }
    });
  },

  // 支付预约
  pay(id, paymentMethod) {
    return app.request({
      url: `/reservations/${id}/pay`,
      method: 'POST',
      data: { payment_method: paymentMethod }
    });
  }
};

// 用户相关API
const user = {
  // 获取用户信息
  getProfile() {
    return app.request({
      url: '/user/profile'
    });
  },

  // 更新用户信息
  updateProfile(data) {
    return app.request({
      url: '/user/profile',
      method: 'PUT',
      data
    });
  }
};

export default {
  schedule,
  reservation,
  user
};